DEFINITION MODULE EventMgr;     (* Franz Kronseder 08.01.85 *)
                                (* MacIntosh ToolBox Event Manager Operations *)
                                (* last modified   09.06.85 fxk *)

IMPORT MacBase; FROM MacBase IMPORT Point,LongInt; 

EXPORT QUALIFIED
 everyEvent,nullEvent,mouseDown,mouseUp,keyDown,keyUp,autoKey,updateEvt,
 diskEvt,activateEvt,abortEvt,reserveEvt,driverEvt,
 app1Evt,app2Evt,app3Evt,app4Evt,
 nullMask,mDownMask,mUpMask,keyDownMask,keyUpMask,autoKeyMask,updateMask,
 diskMask, activMask,abortMask,reserveMask,driverMask,
 app1Mask,app2Mask,app3Mask,app4Mask,
 optionKey,alphaLock,ShiftKey,CmdKey,BtnState,activeFlag,changeFlag,
 EventRecord,KeyMap,
 EventAvail,GetNextEvent,StillDown,WaitMouseUp,GetMouse,TickCount,Button,
 GetKeys, PostEvent,FlushEvents,SetEventMask,OSEventAvail,GetOSEvent;

CONST
  everyEvent  = -1;
  nullEvent   = 0;  mouseDown   = 1;  mouseUp     = 2;  keyDown     = 3;
  keyUp       = 4;  autoKey     = 5;  updateEvt   = 6;  diskEvt     = 7;
  activateEvt = 8;  abortEvt    = 9;  reserveEvt  = 10; driverEvt   = 11;
  app1Evt     = 12; app2Evt     = 13; app3Evt     = 14; app4Evt     = 15;

  nullMask  =   1; mDownMask   =   2; mUpMask     =    4; keyDownMask   =    8;
  keyUpMask =  16; autoKeyMask =  32; updateMask  =   64; diskMask      =  128;
  activMask = 256; abortMask   = 512; reserveMask = 1024; driverMask    = 2048;
  app1Mask  =4096; app2Mask    =8192; app3Mask    =16384; app4Mask      =8000H; (* -32768 *)


  (* modifiers !!! here Bitnumbers in BITSET !!! *)
  optionKey = 11;    (*2048, Bit 3 of high byte  *)
  alphaLock = 10;    (*1024, Bit 2  *)
  ShiftKey  =  9;    (* 512, Bit 1  *)
  CmdKey    =  8;    (* 256, Bit 0  *)
  BtnState  =  7;    (* 128, Bit 7 of low byte is mouse button state  *)
  activeFlag=  0;    (*   1, bit 0 of modifiers for activate event  *)
  changeFlag=  1;    (*   2, bit 1 of modifiers for activate event  *)

 TYPE  OsErr=MacBase.OsErr;      (* = INTEGER;*)
       KeyMap      = ARRAY[0..3] OF LongInt;(* PACKED ARRAY [1..128] OF BOOLEAN *)

  EventRecord = RECORD
                  what:      INTEGER;
                  CASE BOOLEAN  OF
                    TRUE : message: LongInt;
                  | FALSE: msgchar: ARRAY [0..3] OF CHAR;
                  END;
                  when:      LongInt;
                  where:     Point;
                  CASE BOOLEAN OF
                    TRUE : modifiers: BITSET;
                  | FALSE: modifwrd : CARDINAL; (* modifier word *)
                  END;
                END;  (* record *)

PROCEDURE EventAvail  (mask:INTEGER; VAR theEvent: EventRecord): BOOLEAN;(* INLINE $A971 *)
PROCEDURE GetNextEvent(mask:INTEGER; VAR theEvent: EventRecord): BOOLEAN;(* INLINE $A970 *)
PROCEDURE StillDown   ():BOOLEAN;                                        (* INLINE $A973 *)
PROCEDURE WaitMouseUp ():BOOLEAN;                                        (* INLINE $A977 *)
PROCEDURE GetMouse    (VAR pt: Point);                                   (* INLINE $A972 *)
PROCEDURE TickCount   ():LongInt;                                        (* INLINE $A975 *)
PROCEDURE Button      ():BOOLEAN;                                        (* INLINE $A974 *)
PROCEDURE GetKeys     (VAR k: KeyMap);                                   (* INLINE $A976 *)

PROCEDURE PostEvent   (eventNum: INTEGER; eventMsg: LongInt): OsErr;
PROCEDURE FlushEvents (whichMask,stopMask: INTEGER);
(************** These Routines are not yet implemented *******************)
PROCEDURE SetEventMask(theMask: INTEGER);
PROCEDURE OSEventAvail(mask: INTEGER; VAR theEvent: EventRecord): BOOLEAN;
PROCEDURE GetOSEvent  (mask: INTEGER; VAR theEvent: EventRecord): BOOLEAN;
(*************************************************************************)

END EventMgr.
